package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@Configuration
public class DemoApplication {

	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(DemoApplication.class, args);
		Object demo1 = context.getBean("demo1");
		Object demo2 = context.getBean("demo2");
		Object demo3 = context.getBean("demo3");
		Object demo = context.getBean("demo");
		System.out.println(demo);
		System.out.println(demo3);
		System.out.println(demo1 == demo2);


		//手动发布一个事件
		context.publishEvent(new ApplicationEvent("我手动发布了一个事件") {
			@Override
			public Object getSource() {
				return super.getSource();
			}
		});
	}

	@Bean
	public Demo demo1() {
		return new Demo();
	}

	@Bean
	public Demo demo2() {
		return new Demo();
	}
}
